package xkp.lesson.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
import xkp.lesson.exception.ConsumerException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyExceptionHandler implements HandlerExceptionResolver {
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        httpServletRequest.setAttribute("ex",e);
      /*  if(e instanceof NullPointerException){
            return new ModelAndView("error");
        }*/
        if(e instanceof ConsumerException){
            return new ModelAndView("consumer-error");
        }

        return new ModelAndView("error");
    }
}
